

<!-- Links For JS CALENDER   -->

<link type="text/css" rel="stylesheet" href="dhtml_calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
	<SCRIPT type="text/javascript" src="dhtml_calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.js?random=20060118"></script>

<!-- End line for JS CALENDER -->

<?php

include("utils.php");
include("lang_buildCustomNetwork.php");
if(!isset($_SESSION[siteuserId]))
echo '<script>location.href="index.php"</script>';

main_content("mainBuySpace();");

function mainBuySpace()
{
if($_SESSION['langId']!="")
{
	$langId=$_SESSION['langId'];
}
else
{
	$langId="1";
}
}


if(isset($_POST['help_insert_main']))
{
print_r($_POST);
$query_campaign = "insert into adcampaign(camp_name,spend_memo,total_budget,daily_budget,start_date,end_date,automatic_charges,charges_amount,start_hour,end_hour,siteuserId) values('".$_POST['camp_name']."','".$_POST['spend_memo']."','".$_POST['total_budget']."','".$_POST['daily_budget_main']."','".$_POST['start_date']."','".$_POST['end_date']."','".$_POST['auto_charge']."','".$_POST['charges_amt']."','".$_POST['start_date_hour']."','".$_POST['end_date_hour']."','".$_SESSION[siteuserId]."') ";


mysql_query($query_campaign);

$insert_id = mysql_insert_id();

$query_campaign_adgroup = "insert into adgroup(adgroup_name,adgroup_daily_budget,adgroup_network,siteuserId,campaign_id) values('".$_POST['add_gr_name']."','".$_POST['daily_budget']."','".$_POST['network']."','".$_SESSION[siteuserId]."','".$insert_id."') ";

$res_campaign_adgroup = mysql_query($query_campaign_adgroup);

$total = $_POST['TOTAL_FILE'];

for($i=1;$i<$total;$i++)
{
if(isset($_POST['add_gr_name'.$i]) && $_POST['add_gr_name'.$i] != ''){
 $query_campaign_adgroup = "insert into adgroup(adgroup_name,adgroup_daily_budget,adgroup_network,siteuserId,campaign_id) values('".$_POST['add_gr_name'.$i]."','".$_POST['daily_budget'.$i]."','".$_POST['network'.$i]."','".$_SESSION[siteuserId]."','".$insert_id."') ";


$res_campaign_adgroup = mysql_query($query_campaign_adgroup);

$adgroup_insert_id = mysql_insert_id();

$formid = 'createad'.$i;
$query_ad = "select * from temp_adgroup_ad where form_id = '".$formid."' ";
$res_ad = mysql_query($query_ad);

while($row_ad = mysql_fetch_array($res_ad))
{
$insert = "insert into adgroup_ad(`adgroup_id`, `heading`, `ad_description`, `dest_url`, `personal_reference`, `campaign_id`) values('".$adgroup_insert_id."','".$row_ad['heading']."','".$row_ad['ad_description']."','".$row_ad['dest_url']."','".$row_ad['personal_reference']."','".$insert_id."') ";

mysql_query($insert);


}
								      }

}

//echo "<script type='text/javascript'>alert('Successfully Added Campaign');</script>";
}


?>

<script type="text/javascript">

window.onunload = delete_garbage_adgrp();

function delete_garbage_adgrp()
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {

//alert(xmlHttp.responseText);	  
      }
    }

  xmlHttp.open("GET","delete_garbage_adgroup.php",true);
  xmlHttp.send(null);
  return false; 
}

function make_div(gFiles)
{

window.open('http://esolz.org/admobweb/advertiser_direct_popup.php?form_id=createad'+ gFiles +'' ,'popup','width=800,height=500,scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=50,top=50'); return false;
}

var gFiles = 1;

function adddiv() 
{ 
    var tr = document.createElement('tr');
    tr.setAttribute('id', 'adgroup' + gFiles);
    var td = document.createElement('td');
    td.innerHTML = '<table name="createad'+gFiles+'" id="createad'+gFiles+'" method="post"><table bgcolor="#CCCCCC"><TR><TD>Ad Type: Text</TD><td>Units: CPC</td></TR><TR><TD>Ad Group Name</TD><td><input type="text" name="add_gr_name'+gFiles+'" id="add_gr_name'+gFiles+'"></td></TR><TR><TD></TD><td id="validate_add_gr_name'+gFiles+'" style="display:none;"></td></TR><TR><TD>Daily Budget</TD><td><input type="text" name="daily_budget'+gFiles+'" id="daily_budget'+gFiles+'"></td></TR><TR><TD>Network</TD><td><select name="network'+gFiles+'" id="network'+gFiles+'"><option value="Select Network">Select Network</option><option value="1">1</option><option value="1">2</option><option value="1">3</option></select></td></TR><TR><TD></TD><td id="validate_network'+gFiles+'" style="display:none;"></td></TR><TR><TD id="tdCreateAdcreatead'+gFiles+'" colspan="2"></TD></TR><TR><TD><input type="submit" name="remove'+gFiles+'" id="remove'+gFiles+'" value="Remove" onclick="removeFile(\'adgroup' + gFiles + '\')"></TD><td><input type="button" name="create_ad'+gFiles+'" id="create_ad'+gFiles+'" value="Create Ad" onclick ="make_div(' + gFiles + ')" ></td></TR></table></table><br>';

    tr.appendChild(td);
    document.getElementById('adgroup').appendChild(tr);
	gFiles++;
  	document.getElementById('TOTAL_FILE').value=gFiles;
	alert(document.getElementById('TOTAL_FILE').value);
	
}

function validate_sub_adgroup(id)
{

var ad_main_group = document.getElementById("add_gr_name"+id).value;
var network = document.getElementById("network"+id).value;

if(network != "Select Network")    {
        document.getElementById("validate_network"+id).style.display="none";
    }

if(ad_main_group != "")    {
        document.getElementById("validate_add_gr_name"+id).style.display="none";
    }



if(ad_main_group == "")    {
        document.getElementById("validate_add_gr_name"+id).style.display="block";
        document.getElementById("validate_add_gr_name"+id).innerHTML="Please Enter Ad Group Name!";
        document.getElementById("add_gr_name"+id).focus();
        return false;
    }

    

   if(network == "Select Network")    {
        document.getElementById("validate_network"+id).style.display="block";
        document.getElementById("validate_network"+id).innerHTML="Please Enter Network!";       
        document.getElementById("network"+id).focus();
        return false;
    }
   
     
ading_adgroup(id);
return true;
}



function removeFile(aId) 
{
    var obj = document.getElementById(aId);
    obj.parentNode.removeChild(obj);
//alert(gFiles);
}



function ading_adgroup(div_id)
{
var div_id = div_id;

var ad_gr_name = document.getElementById('add_gr_name'+div_id).value;
var dail_bud = document.getElementById('daily_budget'+div_id).value;
var network = document.getElementById('network'+div_id).value;


var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {

//alert(xmlHttp.responseText);	  
      }
    }

  xmlHttp.open("GET","adgroup_ajax.php?ad_gr_name="+ad_gr_name+"&dail_bud="+dail_bud+"&network="+network,true);
  xmlHttp.send(null);
  return false; 
}


function add_main()
{

var ad_gr_name = document.getElementById('add_gr_name').value;
var dail_bud = document.getElementById('daily_budget').value;
var network = document.getElementById('network').value;

var xmlHttp;

try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
        document.getElementById("main_adgroup_save").style.display="block";
        document.getElementById("main_adgroup_save").innerHTML="Successfully Saved";
//alert(xmlHttp.responseText);	  
      }
    }

  xmlHttp.open("GET","add_main_ajax.php?ad_gr_name="+ad_gr_name+"&dail_bud="+dail_bud+"&network="+network,true);
  xmlHttp.send(null);
  return false; 
}




function validate_main_adgroup()
{


var ad_main_group = document.getElementById("add_gr_name").value;
var network = document.getElementById("network").value;

if(network != "Select Network")    {
        document.getElementById("validate_network").style.display="none";
    }

if(ad_main_group != "")    {
        document.getElementById("validate_add_gr_name").style.display="none";
    }



if(ad_main_group == "")    {

        document.getElementById("validate_add_gr_name").style.display="block";
        document.getElementById("validate_add_gr_name").innerHTML="Please Enter Ad Group Name!";
        document.getElementById("add_gr_name").focus();
        return false;
    }

    

   if(network == "Select Network")    {
        document.getElementById("validate_network").style.display="block";
        document.getElementById("validate_network").innerHTML="Please Enter Network!";       
        document.getElementById("network").focus();
        return false;
    }
   
     

add_main();
return true;
}


function validate_main_campaign()
{


if(camp_name != "")    		{
        document.getElementById("validate_camp_name").style.display="none";
    }

if(total_budget != "")   	{
        document.getElementById("validate_total_budget").style.display="none";
    }

if(daily_budget_main != "")     {
        document.getElementById("validate_daily_budget_main").style.display="none";
    }

if(start_date != "")    	{
        document.getElementById("validate_start_date").style.display="none";
    }

if(charges_amt != "")    	{
        document.getElementById("validate_charges_amt").style.display="none";
    }


var camp_name = document.getElementById("camp_name").value;
if(camp_name == "")    {

        document.getElementById("validate_camp_name").style.display="block";
        document.getElementById("validate_add_gr_name").innerHTML="Please Enter Ad Group Name!";
        document.getElementById("camp_name").focus();
        return false;
    }


var total_budget = document.getElementById("total_budget").value;
if(total_budget == "")    {

        document.getElementById("validate_total_budget").style.display="block";
        document.getElementById("validate_add_gr_name").innerHTML="Please Enter Total Budget";
        document.getElementById("total_budget").focus();
        return false;
    }


var daily_budget_main = document.getElementById("daily_budget_main").value;
if(daily_budget_main == "")    {

        document.getElementById("validate_daily_budget_main").style.display="block";
        document.getElementById("validate_daily_budget_main").innerHTML="Please Enter Daily Budget";
        document.getElementById("daily_budget_main").focus();
        return false;
    }


var start_date = document.getElementById("start_date").value;
if(start_date == "")    {

        document.getElementById("validate_start_date").style.display="block";
        document.getElementById("validate_start_date").innerHTML="Please Enter Start Date";
        document.getElementById("start_date").focus();
        return false;
    }

var charges_amt = document.getElementById("charges_amt").value;
if(charges_amt == "")    {

        document.getElementById("validate_charges_amt").style.display="block";
        document.getElementById("validate_charges_amt").innerHTML="Please Enter Charges Amount";
        document.getElementById("charges_amt").focus();
        return false;
    }

/////////////////Start of Ad Group validation 

var ad_main_group = document.getElementById("add_gr_name").value;
var network = document.getElementById("network").value;

if(network != "Select Network")    {
        document.getElementById("validate_network").style.display="none";
    }

if(ad_main_group != "")    {
        document.getElementById("validate_add_gr_name").style.display="none";
    }



if(ad_main_group == "")    {

        document.getElementById("validate_add_gr_name").style.display="block";
        document.getElementById("validate_add_gr_name").innerHTML="Please Enter Ad Group Name!";
        document.getElementById("add_gr_name").focus();
        return false;
    }

    

   if(network == "Select Network")    {
        document.getElementById("validate_network").style.display="block";
        document.getElementById("validate_network").innerHTML="Please Enter Network!";       
        document.getElementById("network").focus();
        return false;
    }
//alert(gFiles);
for(i=1;i<gFiles;i++)
{

if(document.getElementById("createad"+i))
{

var ad_main_group = document.getElementById("add_gr_name"+i).value;
var network = document.getElementById("network"+i).value;


if(ad_main_group != "")    {
        document.getElementById("validate_add_gr_name"+i).style.display="none";
    }

if(network != "Select Network")    {
        document.getElementById("validate_network"+i).style.display="none";
    }

if(ad_main_group == "")    {
        document.getElementById("validate_add_gr_name"+i).style.display="block";
        document.getElementById("validate_add_gr_name"+i).innerHTML="Please Enter Ad Group Name!";
        document.getElementById("add_gr_name"+i).focus();
        return false;
    }

    

   if(network == "Select Network")    {
        document.getElementById("validate_network"+i).style.display="block";
        document.getElementById("validate_network"+i).innerHTML="Please Enter Network!";       
        document.getElementById("network"+i).focus();
        return false;
    }

}

}
// End of Ad Group validation /////////////////

// Start Same Ad Group name validation

for(var j=1;j<gFiles;j++)//For main Adgroup
	{

	if(document.getElementById("createad"+i)){
		if(document.getElementById("add_gr_name").value == document.getElementById("add_gr_name"+j).value)
		{
			alert('Adgroup Name should be unique for a Campaign');
			document.getElementById("add_gr_name"+j).focus();
			return false;
		}				 }
	}

for(i=1;i<gFiles;i++)//For dynamic Adgroup
	{
		for(j=1;j<gFiles;j++)//For dynamic Adgroup
		{
			if(document.getElementById("createad"+i)){
				if(document.getElementById("createad"+j)){

			if(i!=j){
			if(document.getElementById("add_gr_name"+i).value == document.getElementById("add_gr_name"+j).value)
			{
				alert('Adgroup Name should be unique for a Campaign');
				document.getElementById("add_gr_name"+j).focus();
				return false;
			}
				}
									  }
								 }
		}
	}

// Start Same Ad Group name validation

create_campaign.submit();

}
</script>


<table width="827" border="0" cellpadding="0" cellspacing="0" class="center">
  <tr>
    <td><img src="images/red_table_ltop.jpg" alt="" /></td>
    <td class="red_table_top"></td>
    <td><img src="images/red_tcount($_Post['selcategory']able_rtop.jpg" alt="" /></td>
  </tr>
  <tr>
    <td class="red_table_LSide"></td>
    <!-- ban body part -->
    <td class="inner_contentArea">
	
	<form name="create_campaign" method="POST" id="create_campaign" action="">
	<input name="help_insert_main" id="help_insert_main" value="help_insert_main" type="hidden">		
	<input name="TOTAL_FILE" id="TOTAL_FILE" value="1" type="hidden">


	<table align="center">
		<TR>
			<TD align="center" width="50%" valign="top"><!-- LEFT TD -->
				<table>
					<tr><TD><b><font size="2">Campaign Details</font></b></TD></tr>
					<TR>
						<TD>Name</TD>
						<TD><input type="text" name="camp_name" id="camp_name" /></TD>
					</TR>
					
					<tr>
						<TD></TD>
						<TD style="display:none;" id="validate_camp_name">Please Enter the name</TD>
					</TR>

					<TR>
						<TD>Spend Memo</TD>
						<TD align="left">
							<table align="left">
								<TR><TD><input type="radio" name="spend_memo" value="fast_possible" checked="true"></TD>
								<td>Run ads as fast as possible</td>
								</TR>

								<TR><TD><input type="radio" name="spend_memo" value="all_day"></td><td>Run ads throughout the day</td></TR>
							</table>
						</TD>
					</TR>
					
					
					<TR>
						<TD>Total Budget    $   </TD>
						<TD><inpUT type="text" name="total_budget" id="total_budget"></TD>
					</TR>
					
					<tr>
						<TD></TD>
						<TD style="display:none;" id="validate_total_budget">Please Enter Total Budget</TD>
					</TR>

					<TR>
						<TD>daily Budget</TD>
						<TD><inpUT type="text" name="daily_budget_main" id="daily_budget_main"></TD>
					</TR>
					
					<tr>
						<TD></TD>
						<TD style="display:none;" id="validate_daily_budget_main">Please Enter Daily Budget</TD>
					</TR>

					<TR>
						<TD>Start Date</TD>
						<TD>
							<table>
							<TR>
								


<TD>

 
<input type="text" readonly name="start_date" id="start_date" onclick="displayCalendar(document.create_campaign.start_date,'yyyy/mm/dd',this)">

<!--<inpUT type="text" name="start_date" id="start_date" />-->


</TD>




	
	







								<td>Hour
									<select name="start_date_hour">
										<opTION value="1">1</opTION>
										<opTION value="2">2</opTION>
										<opTION value="3">3</opTION>
										<opTION value="4">4</opTION>
										<opTION value="5">5</opTION>
										<opTION value="6">6</opTION>
										<opTION value="7">7</opTION>
										<opTION value="8">8</opTION>
										<opTION value="9">9</opTION>
										<opTION value="10">10</opTION>
										<opTION value="11">11</opTION>
										<opTION value="12">12</opTION>
										<opTION value="13">13</opTION>
										<opTION value="14">14</opTION>
										<opTION value="15">15</opTION>
										<opTION value="16">16</opTION>
										<opTION value="17">17</opTION>
										<opTION value="18">18</opTION>
										<opTION value="19">19</opTION>
										<opTION value="20">20</opTION>
										<opTION value="21">21</opTION>
										<opTION value="22">22</opTION>
										<opTION value="23">23</opTION>

									</select>
								</td>
							</TR>
							</table>
						</td>
					</TR>
					
					<tr>
						<TD></TD>
						<TD style="display:none;" id="validate_start_date">Please Enter Start Date</TD>
					</TR>

					<TR>
						<TD>End Date</TD>
						<TD>
							<table>
							<TR>
								
<TD>

 
<input type="text" readonly name="end_date" id="end_date" onclick="displayCalendar(document.create_campaign.end_date,'yyyy/mm/dd',this)">
<!--<inpUT type="text" name="start_date" id="start_date" />-->


</TD>	
							<td>Hour
									<select name="end_date_hour">
										<opTION value="1">1</opTION>
										<opTION value="2">2</opTION>
										<opTION value="3">3</opTION>
										<opTION value="4">4</opTION>
										<opTION value="5">5</opTION>
										<opTION value="6">6</opTION>
										<opTION value="7">7</opTION>
										<opTION value="8">8</opTION>
										<opTION value="9">9</opTION>
										<opTION value="10">10</opTION>
										<opTION value="11">11</opTION>
										<opTION value="12">12</opTION>
										<opTION value="13">13</opTION>
										<opTION value="14">14</opTION>
										<opTION value="15">15</opTION>
										<opTION value="16">16</opTION>
										<opTION value="17">17</opTION>
										<opTION value="18">18</opTION>
										<opTION value="19">19</opTION>
										<opTION value="20">20</opTION>
										<opTION value="21">21</opTION>
										<opTION value="22">22</opTION>
										<opTION value="23">23</opTION>

								</select>
								</td>
							</TR>
							</table>
						</td>
					</TR>

				</table>

				<table align="left">
					<TR><TD><font size="2"><b>Replenish Account Balance</b></font></TD></TR>
					<TR>
						<TD>Automatic Charges</TD>
						<td><input type="radio" name="auto_charge" value="yes">Yes</td>
						<td><input type="radio" name="auto_charge" value="no" checked="true">No</td>
					</tr>
					

					<TR>
						<TD>Charges Amount          $</TD>
						</form><td colspan="3"><input type="text" id="charges_amt" name="charges_amt"></td>
						
					</tr>

					<TR>
						<TD></TD>
						<td id="validate_charges_amt" style="display:none;"></td>
						
					</tr>

					<TR>
						<TD>Credit Card</TD>
						<td colspan="3"><input type="submit" name="credit_card" value="Add New" onclick="return validate_main_campaign();"></td>
						
					</tr>

					<tr><TD height="15px"></TD></tr>

<TR><TD colspan="5"><font size="1"><p>
Campaign Ads require approval before they begin running on the network. Ads within an Ad Group will rotate amongst themselves, and compete for placement according to the price paid.</p><p>
form
When pausing an ad, it will continue to serve until the action has replicated throughout our network. During this time, all impressions and clicks will be charged at the ad's bid price.</p></font>

				</TD></TR>
				</table>
	



			</TD>

			<TD align="center" valign="top"><!-- RIGHT TD START  -->
<table>
				<TR><TD>
				<table>
				<TR><TD>Ad Groups  What's this?</TD></TR>
				<TR><TD>Ad Groups:</TD></TR>
				<TR><TD>Ads</TD></TR>
				<TR><TD><input type="button" name="create_ad_group" onclick="return adddiv();" value="Create Ad Group"></TD></TR>
				</table>
</td></tr>
				<TR><TD>
				<div id="adgroup">
				<table name="createad" method="post" id="createad" action="create_campaign.php">
				<input name="help_insert" id="help_insert" value="help_insert" type="hidden">		
					<table bgcolor="#CCCCCC" id>

						<TR><TD>Ad Type: Text</TD><td>	Units: CPC</td></TR>

						<TR><TD>Ad Group Name</TD><td><input type="text" name="add_gr_name" id="add_gr_name"></td></TR>

						<TR><TD></TD><td id="validate_add_gr_name" style="display:none;"></td></TR>

						<TR><TD>Daily Budget</TD><td><input type="text" name="daily_budget" id="daily_budget"></td></TR>

						<TR><TD>Network</TD><td>
						<select name="network" id="network">
							<option value="Select Network">Select Network</option>

							<option value="1">1</option>
							<option value="1">2</option>
							<option value="1">3</option>
						</select>

						</td></TR>

						<TR><TD></TD><td id="validate_network" style="display:none;"></td></TR>

						<TR><TD></TD><td id="main_adgroup_save" style="display:none;"></td></TR>


						<!--<TR><TD></TD><td><input type="button" name="create_ad" id="create_ad" value="Create Ad" onclick="return validate_main_adgroup();"></td></TR>-->
					
						<TR><TD id="tdCreateAdcreatead" colspan="2"></TD></TR>

						<TR><TD></TD><td><input type="button" name="create_ad" id="create_ad" value="Create Ad" onclick="window.open('http://esolz.org/admobweb/advertiser_direct_popup.php?form_id=createad','popup','width=800,height=500,scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=50,top=50'); return false"></td></TR>




					</table>
				</table>
				</div>
</td></tr></table>
			</td><!-- RIGHT TD -->

		</TR>

<tr><TD><inpUT type="submit" value="Save" id="save_all" name="save_all" onclick="return validate_main_campaign();"></TD></tr>
	
</form>	</table>


</TD>

<td class="red_table_RSide"></td>
</tr>
<tr>
  <td><img src="images/red_table_lbottom.jpg" alt="" /></td>
  <td class="red_table_bottom"></td>
  <td><img src="images/red_table_rbottom.jpg" alt="" /></td>
</tr>
</table>

